#include "algorithm.h"

void filter_init(filter_int_t *filter_int, float a, uint8_t precision)
{
	filter_int->precision = precision;
	filter_int->a = a * (0x01 << filter_int->precision);
}

int32_t filter_lp(filter_int_t *filter_int, int32_t input)
{
	filter_int->lp_y *= ((0x01 << filter_int->precision) - filter_int->a);
	filter_int->lp_y += (filter_int->a * input);
	filter_int->lp_y >>= filter_int->precision;
	filter_int->y = filter_int->lp_y;
	return filter_int->y;
}

int32_t filter_hp(filter_int_t *filter_int, int32_t input)
{
	filter_int->y = input - filter_lp(filter_int, input);
	return filter_int->y;
}

uint16_t sin_table[91] = {
	0, 572, 1144, 1716, 2287, 2859, 3430, 4001, 4572, 5142, 5712, 6281, 6850, 7419, 7987, 8554, 9121, 9687, 10252, 10817, 11380, 11943, 12505, 13066, 13626, 14185, 14742, 15299, 15855, 16409, 16962, 17514, 18064, 18613, 19161, 19707, 20252, 20795, 21336, 21876, 22415, 22951, 23486, 24019, 24550, 25080, 25607, 26132, 26656, 27177, 27697, 28214, 28729, 29242, 29753, 30261, 30767, 31271, 31772, 32271, 32768, 33262, 33754, 34242, 34729, 35212, 35693, 36172, 36647, 37120, 37590, 38057, 38521, 38982, 39441, 39896, 40348, 40797, 41243, 41686, 42126, 42562, 42995, 43425, 43852, 44275, 44695, 45112, 45525, 45935, 46341};
